<?php
namespace app\mobile\controller;

use think\Controller;
use think\Exception;
use think\Request;

class Distribution extends Base {

    /**
     * 分销二维码入口
     */
    public function index() {
        $user_id = input('u_id', '');
        $plat_id = input('platid', '');
        if (!isset($user_id) || empty($user_id)) {
            throw new Exception('推荐人缺失');
        }

        // 授权登录验证
        $url = $this->request->url(true);
        $this->init($url);

        $distributionM = new \app\mobile\model\Distribution();
        if (!$distributionM->addChild($user_id)) {
            throw new Exception('服务器繁忙，请联系客服');
        }

        $this->redirect('index/index', ['platid' => $plat_id]);
    }
}